<?php
/*
 * @Author: 哲学家乔布斯 <wuyangii@qq.com>
 * @Date: 2022-10-25 20:19:21
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2022-10-25 20:22:43
 * @Descripttion: 
 */


namespace app\common\model;

use think\Model;

class AgentGoods extends Base
{
    protected $insert = ['addtime','image'];
    protected $update = ['image'];

    //---------------自动完成----------------------
    protected function setAddtimeAttr()
    {
        return time();
    }

    protected function setImageAttr($value)
    {
        return empty($value) ? json_encode([]) : json_encode($value);
    }


    public function getImageTextAttr($value,$data){
        return $data['image'] ? cdnurl($data['image'],true) : "";
    }
     /**
     * @description: 分类名称
     * @param {*} $value
     * @param {*} $data
     * @return {*}
     */    
    public function getCateTitleAttr($value,$data){
        return (new \app\common\model\GoodsCate())->where(['id' => $data['cate_id']])->value('title');
    }
   
    public function getGoodsTypeTitleAttr($value,$data){
        return (new \app\common\model\GoodsType())->where(['id' => $data['goods_type_id']])->value('title');
    }
    public function getSalesAttr($value,$data){
         $data = (new \app\common\model\Goods())->where(['id' => $data['id']])->find();
         return $data['z_sales']+$data['x_sales']; 
    }
    
    /**
     * 获取图片数组
     *
     * @param [type] $value
     * @param [type] $data
     * @return void
     */
    public function getImageAttr($value, $data)
    {
        $array = empty($data['image']) ? [] : json_decode($data['image'], true);
        return $array;
    }

    /**
     * 获取图片数组
     *
     * @param [type] $value
     * @param [type] $data
     * @return void
     */
    public function getCoverImageTextAttr($value, $data)
    {
        return cdnurl($data['cover_image'],true);
    }

    public function getMoneyAttr($value,$data){
        return (new \app\common\model\GoodsSku())->where(['is_default' => 1])->value('money');
    }
    public function getSkuAttr($value,$data){
        return (new \app\common\model\GoodsSku())->field(['id','sku_title','money'])->where(['goods_id' => $data['id']])->select();
    }
    public function getBusUserNameAttr($value,$data){
        return (new \app\common\model\Bus())->where(['id' => $data['bus_id']])->value('user_name');
    }
    public function getAgentUserNameAttr($value,$data){
        return (new \app\common\model\Agent())->where(['id' => $data['agent_id']])->value('usename');
    }


  
}
